<?php
namespace backend\controllers;
use backend\models\SystemAdminOperateRecordModel;
use backend\models\SystemLoginLogModel;
use Yii;
use backend\base\BaseController;
use yii\data\Pagination;

/**
 * 日志管理
 * Class LogController
 * @package backend\controllers
 */
class LogController extends BaseController
{

    /**
     * 登录日志列表
     */
    public function actionSystemLoginList()
    {
        $ip = Yii::$app->request->get('ip','');
        $admin_id = Yii::$app->request->get('admin_id','');
        $input_date = Yii::$app->request->get('input_date','');
        //查询
        $query = SystemLoginLogModel::find();
        if($ip !== ''){
            $query->andFilterWhere(['ip'=>$ip]);
        }
        if($admin_id !== ''){
            $query->andFilterWhere(['admin_id'=>admin_id]);
        }
        if($input_date){
            $input_date_arr = explode('~',$input_date);
            $query->andFilterWhere(['between','create_time',strtotime($input_date_arr[0]),strtotime($input_date_arr[1])]);
        }
        $count = $query->count();
        //分页
        $pagination = new Pagination(['totalCount' => $count]);
        //列表
        $list = $query->offset($pagination->offset)
            ->limit($pagination->limit)
            ->orderBy('id desc')
            ->all();
        return $this->render('system-login-list',['list' => $list,'pagination'=>$pagination,'ip'=>$ip,'admin_id'=> $admin_id,'input_date'=>$input_date]);
    }

    /**
     * 操作日志列表
     */
    public function actionSystemOperateList()
    {
        $admin_id = Yii::$app->request->get('admin_id','');
        $keyword = Yii::$app->request->get('keyword','');
        $input_date = Yii::$app->request->get('input_date','');
        //查询
        $query = SystemAdminOperateRecordModel::find();
        if($admin_id !== ''){
            $query->andFilterWhere(['admin_id'=>admin_id]);
        }
        if($keyword !== ''){
            $query->andFilterWhere(['like','desc',$keyword]);
        }
        if($input_date){
            $input_date_arr = explode('~',$input_date);
            $query->andFilterWhere(['between','create_time',strtotime($input_date_arr[0]),strtotime($input_date_arr[1])]);
        }
        $count = $query->count();
        //分页
        $pagination = new Pagination(['totalCount' => $count]);
        //列表
        $list = $query->offset($pagination->offset)
            ->limit($pagination->limit)
            ->orderBy('id desc')
            ->all();
        return $this->render('system-operate-list',['list' => $list,'pagination'=>$pagination,'admin_id'=> $admin_id,'keyword'=>$keyword,'input_date'=>$input_date]);
    }

}

?>